#ifndef PAGEUARTCONFIG_H
#define PAGEUARTCONFIG_H

#include <QWidget>
#include <QComboBox>
#include <QLabel>
#include <QPushButton>
#include <QLineEdit>
#include <QCheckBox>
#include "serialport.h"

class PageUartConfig : public QWidget
{
    Q_OBJECT
public:
    PageUartConfig(QWidget *parent = nullptr);

    void setSerialPort(SerialPort &port);
    void checkSerialPort();

    void findAvaliblePorts(void);
    void findPortManagerPorts(void);

public slots:
    void onPortChanged(int index);
    void onAvalibleNameChanged(int index);

signals:
    void error(QString str);

private:
    QLabel *lbPort;
    QComboBox *cbPort;

    QLabel *lbAvailableNames;
    QComboBox *cbAvailableNames;
    QLabel *lbName;
    QLineEdit *leName;
    QLabel *lbBaudRate;
    QLabel *lbDataBits;
    QLabel *lbStopBits;
    QLabel *lbParity;
    QComboBox *cbBaudRate;
    QComboBox *cbDataBits;
    QComboBox *cbStopBits;
    QComboBox *cbParity;
    QPushButton *pbFind;
    QPushButton *pbOpen;

    QCheckBox *ckbAutoOpen;
    QPushButton *pbSave;

    // config data
    SerialPortSetting m_setting;
    SerialPort *m_port;

    QList<SerialPort*> m_ports;
};

#endif // PAGEUARTCONFIG_H
